/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PlaylistActionPanel.java
 *
 * Created on Jan 14, 2010, 8:28:04 AM
 */
package com.bff.mpd.musicjukebox.ui.components;

import com.bff.bjj.ui.component.BJJButton;
import com.bff.bjj.ui.component.BJJPanel;
import com.bff.mpd.musicjukebox.lib.JukeboxProperties;
import com.bff.mpd.musicjukebox.lib.actions.PlaylistInsertAlbumAction;
import com.bff.mpd.musicjukebox.lib.actions.PlaylistInsertArtistAction;
import com.bff.mpd.musicjukebox.lib.actions.PlaylistRandomAction;
import com.bff.mpd.musicjukebox.lib.actions.PlaylistRemoveArtistAction;
import com.bff.mpd.musicjukebox.ui.SplashScreen;
import com.bff.mpd.utils.Utils;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Action;
import org.bff.javampd.MPDDatabase;
import org.bff.javampd.MPDPlayer;
import org.bff.javampd.MPDPlaylist;
import org.bff.javampd.exception.MPDConnectionException;
import org.bff.javampd.exception.MPDPlayerException;
import org.bff.javampd.exception.MPDPlaylistException;
import org.bff.javampd.objects.MPDAlbum;
import org.bff.javampd.objects.MPDArtist;
import org.bff.javampd.objects.MPDSong;

/**
 *
 * @author bfindeisen
 */
public class PlaylistActionPanel extends BJJPanel {

    private MPDPlaylist playlist;
    private MPDPlayer player;
    private MPDDatabase database;
    private MPDArtist selectedArtist;
    private MPDAlbum selectedAlbum;
    private MPDSong selectedSong;
    private MPDArtist currentArtist;
    private MPDAlbum currentAlbum;
    private MPDSong currentSong;
    private Action addAlbumAction;
    private Action addArtistAction;
    private Action removeArtistAction;
    private SplashScreen sp;

    /** Creates new form PlaylistActionPanel */
    public PlaylistActionPanel() {
        setPlaylist(JukeboxProperties.getInstance().getPlaylist());
        setPlayer(JukeboxProperties.getInstance().getPlayer());
        setDatabase(JukeboxProperties.getInstance().getDatabase());

        makeActions();
        initComponents();

        disableCurrentActions();
        disableSelectedActions();

        checkRandom();
        
        remove(cbRemoveSong);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        cbRemoveSong = new javax.swing.JCheckBox();
        panelCurrentlyPlaying = new BJJPanel();
        addCurrentArtistButton = new BJJButton();
        addCurrentAlbumButton = new BJJButton();
        removeCurrentArtistButton = new BJJButton();
        removeCurrentAlbumButton = new BJJButton();
        jPanel1 = new BJJPanel();
        jPanel7 = new BJJPanel();
        btnAddArtist = new BJJButton();
        btnRemoveArtist = new BJJButton();
        lblArtist = new javax.swing.JLabel();
        jPanel6 = new BJJPanel();
        btnAddAlbum = new BJJButton();
        btnRemoveAlbum = new BJJButton();
        lblAlbum = new javax.swing.JLabel();
        jPanel2 = new BJJPanel();
        removeButton = new BJJButton();
        removeAllButton = new BJJButton();
        cbRandom = new javax.swing.JCheckBox();

        setLayout(new java.awt.GridBagLayout());

        cbRemoveSong.setText("Remove song after playing");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 0);
        add(cbRemoveSong, gridBagConstraints);

        panelCurrentlyPlaying.setBorder(javax.swing.BorderFactory.createTitledBorder(Utils.getMessage("PLAYLIST_CURRENT_BORDER"))); // NOI18N
        panelCurrentlyPlaying.setLayout(new java.awt.GridBagLayout());

        addCurrentArtistButton.setFont(new java.awt.Font("Tahoma", 0, 12));
        addCurrentArtistButton.setText("Add Artist");
        addCurrentArtistButton.setMaximumSize(new java.awt.Dimension(115, 27));
        addCurrentArtistButton.setMinimumSize(new java.awt.Dimension(115, 27));
        addCurrentArtistButton.setPreferredSize(new java.awt.Dimension(115, 27));
        addCurrentArtistButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addCurrentArtistButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
        panelCurrentlyPlaying.add(addCurrentArtistButton, gridBagConstraints);

        addCurrentAlbumButton.setFont(new java.awt.Font("Tahoma", 0, 12));
        addCurrentAlbumButton.setText("Add Album");
        addCurrentAlbumButton.setMaximumSize(new java.awt.Dimension(115, 27));
        addCurrentAlbumButton.setMinimumSize(new java.awt.Dimension(115, 27));
        addCurrentAlbumButton.setPreferredSize(new java.awt.Dimension(115, 27));
        addCurrentAlbumButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addCurrentAlbumButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
        panelCurrentlyPlaying.add(addCurrentAlbumButton, gridBagConstraints);

        removeCurrentArtistButton.setFont(new java.awt.Font("Tahoma", 0, 12));
        removeCurrentArtistButton.setText("Remove Artist");
        removeCurrentArtistButton.setMaximumSize(new java.awt.Dimension(115, 27));
        removeCurrentArtistButton.setMinimumSize(new java.awt.Dimension(115, 27));
        removeCurrentArtistButton.setPreferredSize(new java.awt.Dimension(115, 27));
        removeCurrentArtistButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeCurrentArtistButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
        panelCurrentlyPlaying.add(removeCurrentArtistButton, gridBagConstraints);

        removeCurrentAlbumButton.setFont(new java.awt.Font("Tahoma", 0, 12));
        removeCurrentAlbumButton.setText("Remove Album");
        removeCurrentAlbumButton.setMaximumSize(new java.awt.Dimension(115, 27));
        removeCurrentAlbumButton.setMinimumSize(new java.awt.Dimension(115, 27));
        removeCurrentAlbumButton.setPreferredSize(new java.awt.Dimension(115, 27));
        removeCurrentAlbumButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeCurrentAlbumButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
        panelCurrentlyPlaying.add(removeCurrentAlbumButton, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        add(panelCurrentlyPlaying, gridBagConstraints);

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("Artist"));
        jPanel7.setLayout(new java.awt.GridBagLayout());

        btnAddArtist.setFont(new java.awt.Font("Tahoma", 0, 12));
        btnAddArtist.setText("Add Artist");
        btnAddArtist.setMaximumSize(new java.awt.Dimension(115, 27));
        btnAddArtist.setMinimumSize(new java.awt.Dimension(115, 27));
        btnAddArtist.setPreferredSize(new java.awt.Dimension(115, 27));
        btnAddArtist.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddArtistActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
        jPanel7.add(btnAddArtist, gridBagConstraints);

        btnRemoveArtist.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnRemoveArtist.setText("Remove Artist");
        btnRemoveArtist.setMaximumSize(new java.awt.Dimension(115, 27));
        btnRemoveArtist.setMinimumSize(new java.awt.Dimension(115, 27));
        btnRemoveArtist.setPreferredSize(new java.awt.Dimension(115, 27));
        btnRemoveArtist.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoveArtistActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
        jPanel7.add(btnRemoveArtist, gridBagConstraints);

        lblArtist.setText("                    ");
        jPanel7.add(lblArtist, new java.awt.GridBagConstraints());

        jPanel1.add(jPanel7);

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Album"));
        jPanel6.setLayout(new java.awt.GridBagLayout());

        btnAddAlbum.setFont(new java.awt.Font("Tahoma", 0, 12));
        btnAddAlbum.setText("Add Album");
        btnAddAlbum.setMaximumSize(new java.awt.Dimension(115, 27));
        btnAddAlbum.setMinimumSize(new java.awt.Dimension(115, 27));
        btnAddAlbum.setPreferredSize(new java.awt.Dimension(115, 27));
        btnAddAlbum.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddAlbumActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
        jPanel6.add(btnAddAlbum, gridBagConstraints);

        btnRemoveAlbum.setFont(new java.awt.Font("Tahoma", 0, 12));
        btnRemoveAlbum.setText("Remove Album");
        btnRemoveAlbum.setMaximumSize(new java.awt.Dimension(115, 27));
        btnRemoveAlbum.setMinimumSize(new java.awt.Dimension(115, 27));
        btnRemoveAlbum.setPreferredSize(new java.awt.Dimension(115, 27));
        btnRemoveAlbum.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoveAlbumActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
        jPanel6.add(btnRemoveAlbum, gridBagConstraints);

        lblAlbum.setText("                    ");
        jPanel6.add(lblAlbum, new java.awt.GridBagConstraints());

        jPanel1.add(jPanel6);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Playlist"));
        jPanel2.setLayout(new java.awt.GridBagLayout());

        removeButton.setFont(new java.awt.Font("Tahoma", 0, 12));
        removeButton.setText("Remove");
        removeButton.setMaximumSize(new java.awt.Dimension(115, 27));
        removeButton.setMinimumSize(new java.awt.Dimension(115, 27));
        removeButton.setPreferredSize(new java.awt.Dimension(115, 27));
        removeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeButtonActionPerformed(evt);
            }
        });
        jPanel2.add(removeButton, new java.awt.GridBagConstraints());

        removeAllButton.setFont(new java.awt.Font("Tahoma", 0, 12));
        removeAllButton.setText("Clear");
        removeAllButton.setMaximumSize(new java.awt.Dimension(115, 27));
        removeAllButton.setMinimumSize(new java.awt.Dimension(115, 27));
        removeAllButton.setPreferredSize(new java.awt.Dimension(115, 27));
        removeAllButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeAllButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        jPanel2.add(removeAllButton, gridBagConstraints);

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("resources/mpd/messages"); // NOI18N
        cbRandom.setText(bundle.getString("RANDOM_TITLE")); // NOI18N
        cbRandom.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbRandomActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        jPanel2.add(cbRandom, gridBagConstraints);

        jPanel1.add(jPanel2);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        add(jPanel1, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

    private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
        try {
            setCursor(Utils.getHourglassCursor());

            getPlaylist().removeSong(getSelectedSong());
        } catch (MPDConnectionException ex) {
            Logger.getLogger(PlaylistActionPanel.class.getName()).log(Level.SEVERE, null, ex);
        } catch (MPDPlaylistException ex) {
            Logger.getLogger(PlaylistActionPanel.class.getName()).log(Level.SEVERE, null, ex);


        } finally {
            setCursor(Utils.getNormalCursor());
        }
}//GEN-LAST:event_removeButtonActionPerformed

    private void addCurrentArtistButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addCurrentArtistButtonActionPerformed
        try {
            setCursor(Utils.getHourglassCursor());
            getPlaylist().insertArtist(getPlaylist().getCurrentSong().getArtist());
        } catch (MPDConnectionException ex) {
            Logger.getLogger(PlaylistActionPanel.class.getName()).log(Level.SEVERE, null, ex);
        } catch (MPDPlaylistException ex) {
            Logger.getLogger(PlaylistActionPanel.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            setCursor(Utils.getNormalCursor());
        }
}//GEN-LAST:event_addCurrentArtistButtonActionPerformed

    private void addCurrentAlbumButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addCurrentAlbumButtonActionPerformed
        try {
            setCursor(Utils.getHourglassCursor());
            getPlaylist().insertAlbum(getPlaylist().getCurrentSong().getArtist(),
                    getPlaylist().getCurrentSong().getAlbum());
        } catch (MPDConnectionException ex) {
            Logger.getLogger(PlaylistActionPanel.class.getName()).log(Level.SEVERE, null, ex);
        } catch (MPDPlaylistException ex) {
            Logger.getLogger(PlaylistActionPanel.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            setCursor(Utils.getNormalCursor());
        }
}//GEN-LAST:event_addCurrentAlbumButtonActionPerformed

    private void removeAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeAllButtonActionPerformed

        sp = new SplashScreen(Utils.getParentComponent(this), false);
        sp.setIndeterminate(true);
        sp.setTitleLabel(Utils.getMessage("PROGRESS_CLEAR_TITLE"));
        sp.setMainTextArea("\n" + Utils.getMessage("PROGRESS_CLEAR_TEXT") + "\n\n");
        sp.setProgressBarLabel(Utils.getMessage("PROGRESS_CLEAR_LABEL"));
        sp.pack();

        new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    setCursor(Utils.getHourglassCursor());
                    while (!sp.isVisible()) {
                        try {
                            Thread.sleep(500);
                        } catch (InterruptedException ex) {
                            Logger.getLogger(PlaylistActionPanel.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                    sp.toFront();
                    getPlaylist().clearPlaylist();
                } catch (MPDConnectionException ex) {
                    Logger.getLogger(PlaylistActionPanel.class.getName()).log(Level.SEVERE, null, ex);
                } catch (MPDPlaylistException ex) {
                    Logger.getLogger(PlaylistActionPanel.class.getName()).log(Level.SEVERE, null, ex);
                } finally {
                    setCursor(Utils.getNormalCursor());
                    sp.setStopped(true);
                }
            }
        }).start();

}//GEN-LAST:event_removeAllButtonActionPerformed

    private void removeCurrentAlbumButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeCurrentAlbumButtonActionPerformed
        try {
            setCursor(Utils.getHourglassCursor());
            getPlaylist().removeAlbum(getPlaylist().getCurrentSong().getArtist(),
                    getPlaylist().getCurrentSong().getAlbum());
        } catch (MPDConnectionException ex) {
            Logger.getLogger(PlaylistActionPanel.class.getName()).log(Level.SEVERE, null, ex);
        } catch (MPDPlaylistException ex) {
            Logger.getLogger(PlaylistActionPanel.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            setCursor(Utils.getNormalCursor());
        }
}//GEN-LAST:event_removeCurrentAlbumButtonActionPerformed

    private void removeCurrentArtistButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeCurrentArtistButtonActionPerformed
        try {
            setCursor(Utils.getHourglassCursor());
            getPlaylist().removeArtist(getPlaylist().getCurrentSong().getArtist());
        } catch (MPDConnectionException ex) {
            Logger.getLogger(PlaylistActionPanel.class.getName()).log(Level.SEVERE, null, ex);
        } catch (MPDPlaylistException ex) {
            Logger.getLogger(PlaylistActionPanel.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            setCursor(Utils.getNormalCursor());
        }
}//GEN-LAST:event_removeCurrentArtistButtonActionPerformed

    private void btnAddAlbumActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddAlbumActionPerformed
        try {
            getPlaylist().insertAlbum(getSelectedArtist(), getSelectedAlbum());
        } catch (MPDConnectionException ex) {
            Logger.getLogger(PlaylistActionPanel.class.getName()).log(Level.SEVERE, null, ex);
        } catch (MPDPlaylistException ex) {
            Logger.getLogger(PlaylistActionPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btnAddAlbumActionPerformed

    private void btnAddArtistActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddArtistActionPerformed
    }//GEN-LAST:event_btnAddArtistActionPerformed

    private void btnRemoveArtistActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveArtistActionPerformed
    }//GEN-LAST:event_btnRemoveArtistActionPerformed

    private void btnRemoveAlbumActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveAlbumActionPerformed
        try {
            getPlaylist().removeAlbum(getSelectedArtist(), getSelectedAlbum());
        } catch (MPDConnectionException ex) {
            Logger.getLogger(PlaylistActionPanel.class.getName()).log(Level.SEVERE, null, ex);
        } catch (MPDPlaylistException ex) {
            Logger.getLogger(PlaylistActionPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btnRemoveAlbumActionPerformed

    private void cbRandomActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbRandomActionPerformed
        try {
            player.setRandom(cbRandom.isSelected());
        } catch (MPDConnectionException ex) {
            Logger.getLogger(PlaylistRandomAction.class.getName()).log(Level.SEVERE, null, ex);
        } catch (MPDPlayerException ex) {
            Logger.getLogger(PlaylistRandomAction.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_cbRandomActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addCurrentAlbumButton;
    private javax.swing.JButton addCurrentArtistButton;
    private javax.swing.JButton btnAddAlbum;
    private javax.swing.JButton btnAddArtist;
    private javax.swing.JButton btnRemoveAlbum;
    private javax.swing.JButton btnRemoveArtist;
    private javax.swing.JCheckBox cbRandom;
    private javax.swing.JCheckBox cbRemoveSong;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JLabel lblAlbum;
    private javax.swing.JLabel lblArtist;
    private javax.swing.JPanel panelCurrentlyPlaying;
    private javax.swing.JButton removeAllButton;
    private javax.swing.JButton removeButton;
    private javax.swing.JButton removeCurrentAlbumButton;
    private javax.swing.JButton removeCurrentArtistButton;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the playlist
     */
    public MPDPlaylist getPlaylist() {
        return playlist;
    }

    /**
     * @param playlist the playlist to set
     */
    private void setPlaylist(MPDPlaylist playlist) {
        this.playlist = playlist;
    }

    private void makeActions() {
        addAlbumAction = new PlaylistInsertAlbumAction(getPlaylist(), getSelectedAlbum(), getSelectedArtist());
        addArtistAction = new PlaylistInsertArtistAction(getPlaylist(), getSelectedArtist());
        removeArtistAction = new PlaylistRemoveArtistAction(getPlaylist(), getSelectedArtist());
    }

    public void setSelectedArtist(MPDArtist artist) {
        addArtistAction = new PlaylistInsertArtistAction(getPlaylist(), artist);
        removeArtistAction = new PlaylistRemoveArtistAction(getPlaylist(), artist);
        btnAddArtist.setAction(addArtistAction);
        btnRemoveArtist.setAction(removeArtistAction);
        lblArtist.setText(artist.getName().length() < 20 ? artist.getName() : artist.getName().substring(0, 20));
        lblArtist.setToolTipText(artist.getName());
    }

    public void setSelectedAlbum(MPDAlbum album) {
        this.selectedAlbum = album;
        lblAlbum.setText(album.getName().length() < 20 ? album.getName() : album.getName().substring(0, 20));
        lblAlbum.setToolTipText(album.getName());
    }

    private void checkRandom() {
        try {
            if (player.isRandom()) {
                cbRandom.setSelected(true);
            } else {
                cbRandom.setSelected(false);
            }
        } catch (MPDConnectionException ex) {
            Logger.getLogger(PlaylistActionPanel.class.getName()).log(Level.SEVERE, null, ex);
        } catch (MPDPlayerException ex) {
            Logger.getLogger(PlaylistActionPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void setSelectedSong(MPDSong song) {
        this.selectedSong = song;
    }

    public void disableSelectedActions() {
        setSelectedAbility(false);
    }

    public void disableCurrentActions() {
        setCurrentAbility(false);
    }

    public void enableSelectedActions() {
        setSelectedAbility(true);
    }

    public void enableCurrentActions() {
        setCurrentAbility(true);
    }

    /**
     * @return the database
     */
    public MPDDatabase getDatabase() {
        return database;
    }

    /**
     * @param database the database to set
     */
    private void setDatabase(MPDDatabase database) {
        this.database = database;
    }

    /**
     * @return the player
     */
    public MPDPlayer getPlayer() {
        return player;
    }

    /**
     * @param player the player to set
     */
    private void setPlayer(MPDPlayer player) {
        this.player = player;
    }

    /**
     * @return the selectedArtist
     */
    public MPDArtist getSelectedArtist() {
        return selectedArtist;
    }

    /**
     * @return the selectedAlbum
     */
    public MPDAlbum getSelectedAlbum() {
        return selectedAlbum;
    }

    /**
     * @return the selectedSong
     */
    public MPDSong getSelectedSong() {
        return selectedSong;
    }

    /**
     * @return the currentArtist
     */
    public MPDArtist getCurrentArtist() {
        return currentArtist;
    }

    /**
     * @param currentArtist the currentArtist to set
     */
    public void setCurrentArtist(MPDArtist currentArtist) {
        this.currentArtist = currentArtist;
    }

    /**
     * @return the currentAlbum
     */
    public MPDAlbum getCurrentAlbum() {
        return currentAlbum;
    }

    /**
     * @param currentAlbum the currentAlbum to set
     */
    public void setCurrentAlbum(MPDAlbum currentAlbum) {
        this.currentAlbum = currentAlbum;
    }

    /**
     * @return the currentSong
     */
    public MPDSong getCurrentSong() {
        return currentSong;
    }

    /**
     * @param currentSong the currentSong to set
     */
    public void setCurrentSong(MPDSong currentSong) {
        this.currentSong = currentSong;
    }

    private void setSelectedAbility(boolean b) {
        btnAddAlbum.setEnabled(b);
        btnRemoveAlbum.setEnabled(b);
        btnAddArtist.setEnabled(b);
        btnRemoveArtist.setEnabled(b);
    }

    private void setCurrentAbility(boolean b) {
        removeCurrentAlbumButton.setEnabled(b);
        removeCurrentArtistButton.setEnabled(b);
        addCurrentAlbumButton.setEnabled(b);
        addCurrentArtistButton.setEnabled(b);
    }

    public boolean isRemoveSong() {
        return cbRemoveSong.isSelected();
    }
}
